{{extend 'layout.html'}}

{{import os, time}}
{{preview_dir=request.application + '/static/book/preview/'}}
{{image='/' + preview_dir + filename}}
{{image_download=preview_dir.replace("preview", "download") + \
    filename.replace("_preview", "")}}

<script type="text/javascript">
$(function () {
  var img = new Image();

  $(img).load(function () {
      $(this).hide();
      $('div#preview').removeClass('loading');
      $('div#preview span a').append(this);
      $(this).css('margin', 'auto');
      $(this).fadeIn();
    })
    .error(function () {})
    .attr('src', "{{=image}}");
});
</script>
<!--{{=BEAUTIFY(request.env)}}-->

{{
  def seconds2date_ctime(filename):
      return time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(os.stat(filename).st_ctime))
}}

<div id="info">
  <span class="preview">
    {{=filename.split('_')[0].upper()}} book
  </span><br /><br />
  <span class="preview">
    <a title="<div class='information'>Download - </div><br />
The black and white version can be downloaded by clicking on the this link."
href={{=URL(r=request,f='download_file',args=[filename])}}>download</a>
  </span>
  <span class="preview">
    <a title="<div class='information'>Preview - </div><br />
The black and white version can be previewed by clicking on the this link or on the picture.<br /><br />
Please note that the picture is 2480x3508 px and some browsers will not shrink it, so you will have to use 
the scoll bars in order to see it." 
href="#" onclick="popup('{{=URL(r=request,f='download_preview',args=[filename])}}')">preview</a>
  </span>
  <span class="preview">
    <a title="<div class='information'>Information - </div><br />
<div class='title'>visits</div><div class='value'>{{=visits}}</div>
<div class='title'>downloads</div><div class='value'>{{=downloads}}</div>
<div class='title'>filename</div><div class='value'>{{=filename_download}}</div>
<div class='title'>created at</div><div class='value'>{{=seconds2date_ctime(request.env.web2py_path + '/applications/' + image_download)}}</div>
<!-- <div class='title'>specs</div><div class='value'>8-bit/color RGBA, non-interlaced</div><br /><br /> -->
<div class='title'>size</div><div class='value'>{{=os.path.getsize(request.env.web2py_path + '/applications/' + image_download)/1024}} Kbytes</div>"
href="#">info</a>
  </span>
</div>
<div id="preview" class="loading">
  <span>
    <a href="#" onclick="popup('{{=URL(r=request,f='download_preview',args=[filename])}}')"></a>
  </span>
</div>